<?php

namespace app\admin\controller\Subject;

use app\common\controller\Backend;

class Chapter extends Backend
{
    /**
     * 当前对象模型
    */
    protected $model = null;

    public function __construct()
    {
        parent::__construct();

        $this->model = model('Subject.Chapter');
    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        

        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }

        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();

        
        $list = $this->model
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);

        $result = ['total' => $list->total(), 'rows' => $list->items()];
        return json($result);
    }
}
